package com.itchen.web.servlet;

import com.alibaba.fastjson.JSON;
import com.itchen.pojo.Province;
import com.itchen.service.ProvinceService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author げっしょく
 * @date 2021/9/6
 */
@WebServlet("/provinceServlet")
public class ProvinceServlet extends HttpServlet {
    private ProvinceService p = new ProvinceService();


    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/json;charset=utf-8");

        List<Province> ps = p.selectAll();

        String s = JSON.toJSONString(ps);

        response.getWriter().write(s);



    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
